package top.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.rmi.runtime.Log;
import top.api.annotation.SystemLog;
import top.api.service.ArticleService;
import top.api.common.ResponseResult;

@RestController
@RequestMapping("/article")
@Slf4j
@Api(tags = "文章")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 查询热门文章
     * @return
     */
    @GetMapping("/hotArticleList")
    @ApiOperation(value = "查询热门文章")
    public ResponseResult hotArticleList(){
        return articleService.hotArticleList();
    }

    /**
     * 分页查询文章
     * @return
     */
    @GetMapping("/articleList")
    @ApiOperation("分页查询文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId",value = "分类列表ID")
    })
    // 加上@RequestParam使参数必须不为null
    public ResponseResult articleList(@RequestParam Integer pageNum, @RequestParam Integer pageSize, Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);
    }

    /**
     * 查询文章详情
    * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查询文章详情")
    public ResponseResult getArticleDetail(@PathVariable Long id){
        return articleService.getArticleDetail(id);
    }

    /**
     * 添加文章阅读访问量
     * @param id
     * @return
     */
    @PutMapping("/updateViewCount/{id}")
    @ApiOperation(value = "添加文章阅读访问量")
    @ApiImplicitParam(name = "id",value = "文章ID")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }
}
